package com.cloudwise.truelicensespringbootstarter.config;

import com.cloudwise.truelicensespringbootstarter.license.common.LicenseVerify;
import com.cloudwise.truelicensespringbootstarter.license.model.LicenseVerifyParam;
import com.cloudwise.truelicensespringbootstarter.properties.LicenseProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @author jeffery.li
 * @date 2022/6/9 14:50
 */
@EnableConfigurationProperties(LicenseProperties.class)
public class LicenseConfig {


    @Autowired
    private LicenseProperties properties;

    @Bean(initMethod = "installLicense", destroyMethod = "unInstallLicense")
    public LicenseVerify licenseVerify() throws Exception{
        LicenseVerifyParam licenseVerifyParam = new LicenseVerifyParam(properties.getSubject(), properties.getPublicAlias()
                , properties.getStorePass(), properties.getLicensePath(), properties.getPublicKeysStorePath());
        return new LicenseVerify(licenseVerifyParam);
    }
}
